const Base = require("../base.js");
const txyoss = require("../public/txyoss");
const puppeteer = require("puppeteer");
module.exports = class extends Base {
  async indexAction() {
    const browser = await puppeteer.launch({
      args: ["--no-sandbox", "--disable-setuid-sandbox"],
    });
    const page = await browser.newPage();
    await page.goto(this.get("url"), {
      //这个可以渲染出图片甚至跨域的图片
      waitUntil: "networkidle2",
    });
    const pdf = await page.pdf({ path: "hn1.pdf", format: "a4",landscape:this.get("landscape")?true:false }); // 如果已有该文件会报错

    let imgurl = await txyoss.upbuff(pdf, "yspdf",".pdf");
    await browser.close();
    this.success(imgurl);
  }
};
